//
// File: fft1.cpp
//
// MATLAB Coder version            : 4.0
// C/C++ source code generated on  : 18-Dec-2020 16:50:24
//

// Include Files
#include <string.h>
#include "rt_nonfinite.h"
#include "sea_parameter_cal.h"
#include "fft1.h"

// Function Declarations
static void b_r2br_r2dit_trig_impl(const creal_T x[4194304], int xoffInit, const
  double costab[129], const double sintab[129], creal_T y[256]);
static void r2br_r2dit_trig_impl(const double x[4194304], int xoffInit, const
  double costab[129], const double sintab[129], creal_T y[256]);

// Function Definitions

//
// Arguments    : const creal_T x[4194304]
//                int xoffInit
//                const double costab[129]
//                const double sintab[129]
//                creal_T y[256]
// Return Type  : void
//
static void b_r2br_r2dit_trig_impl(const creal_T x[4194304], int xoffInit, const
  double costab[129], const double sintab[129], creal_T y[256])
{
  int ix;
  int ju;
  int iy;
  int i;
  boolean_T tst;
  double temp_re;
  double temp_im;
  int iheight;
  int istart;
  int j;
  double twid_re;
  double twid_im;
  int ihi;
  ix = xoffInit;
  ju = 0;
  iy = 0;
  for (i = 0; i < 255; i++) {
    y[iy] = x[ix];
    iy = 256;
    tst = true;
    while (tst) {
      iy >>= 1;
      ju ^= iy;
      tst = ((ju & iy) == 0);
    }

    iy = ju;
    ix++;
  }

  y[iy] = x[ix];
  for (i = 0; i <= 255; i += 2) {
    temp_re = y[i + 1].re;
    temp_im = y[i + 1].im;
    y[i + 1].re = y[i].re - y[i + 1].re;
    y[i + 1].im = y[i].im - y[i + 1].im;
    y[i].re += temp_re;
    y[i].im += temp_im;
  }

  iy = 2;
  ix = 4;
  ju = 64;
  iheight = 253;
  while (ju > 0) {
    for (i = 0; i < iheight; i += ix) {
      temp_re = y[i + iy].re;
      temp_im = y[i + iy].im;
      y[i + iy].re = y[i].re - temp_re;
      y[i + iy].im = y[i].im - temp_im;
      y[i].re += temp_re;
      y[i].im += temp_im;
    }

    istart = 1;
    for (j = ju; j < 128; j += ju) {
      twid_re = costab[j];
      twid_im = sintab[j];
      i = istart;
      ihi = istart + iheight;
      while (i < ihi) {
        temp_re = twid_re * y[i + iy].re - twid_im * y[i + iy].im;
        temp_im = twid_re * y[i + iy].im + twid_im * y[i + iy].re;
        y[i + iy].re = y[i].re - temp_re;
        y[i + iy].im = y[i].im - temp_im;
        y[i].re += temp_re;
        y[i].im += temp_im;
        i += ix;
      }

      istart++;
    }

    ju /= 2;
    iy = ix;
    ix += ix;
    iheight -= iy;
  }
}

//
// Arguments    : const double x[4194304]
//                int xoffInit
//                const double costab[129]
//                const double sintab[129]
//                creal_T y[256]
// Return Type  : void
//
static void r2br_r2dit_trig_impl(const double x[4194304], int xoffInit, const
  double costab[129], const double sintab[129], creal_T y[256])
{
  int ix;
  int ju;
  int iy;
  int i;
  boolean_T tst;
  double temp_re;
  double temp_im;
  int iheight;
  int istart;
  int j;
  double twid_re;
  double twid_im;
  int ihi;
  ix = xoffInit;
  ju = 0;
  iy = 0;
  for (i = 0; i < 255; i++) {
    y[iy].re = x[ix];
    y[iy].im = 0.0;
    iy = 256;
    tst = true;
    while (tst) {
      iy >>= 1;
      ju ^= iy;
      tst = ((ju & iy) == 0);
    }

    iy = ju;
    ix++;
  }

  y[iy].re = x[ix];
  y[iy].im = 0.0;
  for (i = 0; i <= 255; i += 2) {
    temp_re = y[i + 1].re;
    temp_im = y[i + 1].im;
    y[i + 1].re = y[i].re - y[i + 1].re;
    y[i + 1].im = y[i].im - y[i + 1].im;
    y[i].re += temp_re;
    y[i].im += temp_im;
  }

  iy = 2;
  ix = 4;
  ju = 64;
  iheight = 253;
  while (ju > 0) {
    for (i = 0; i < iheight; i += ix) {
      temp_re = y[i + iy].re;
      temp_im = y[i + iy].im;
      y[i + iy].re = y[i].re - temp_re;
      y[i + iy].im = y[i].im - temp_im;
      y[i].re += temp_re;
      y[i].im += temp_im;
    }

    istart = 1;
    for (j = ju; j < 128; j += ju) {
      twid_re = costab[j];
      twid_im = sintab[j];
      i = istart;
      ihi = istart + iheight;
      while (i < ihi) {
        temp_re = twid_re * y[i + iy].re - twid_im * y[i + iy].im;
        temp_im = twid_re * y[i + iy].im + twid_im * y[i + iy].re;
        y[i + iy].re = y[i].re - temp_re;
        y[i + iy].im = y[i].im - temp_im;
        y[i].re += temp_re;
        y[i].im += temp_im;
        i += ix;
      }

      istart++;
    }

    ju /= 2;
    iy = ix;
    ix += ix;
    iheight -= iy;
  }
}

//
// Arguments    : const creal_T x[4194304]
//                const double costab[129]
//                const double sintab[129]
//                creal_T y[4194304]
// Return Type  : void
//
void b_r2br_r2dit_trig(const creal_T x[4194304], const double costab[129], const
  double sintab[129], creal_T y[4194304])
{
  int k;
  creal_T rwork[256];
  int xoff;

#pragma omp parallel for \
 num_threads(omp_get_max_threads()) \
 private(rwork,xoff)

  for (k = 1; k < 16385; k++) {
    xoff = (k - 1) << 8;
    b_r2br_r2dit_trig_impl(x, xoff, costab, sintab, rwork);
    memcpy(&y[(k << 8) + -256], &rwork[0], sizeof(creal_T) << 8);
  }
}

//
// Arguments    : const creal_T x[4194304]
//                const double costab[33]
//                const double sintab[33]
//                creal_T y[4194304]
// Return Type  : void
//
void c_r2br_r2dit_trig(const creal_T x[4194304], const double costab[33], const
  double sintab[33], creal_T y[4194304])
{
  int k;
  creal_T rwork[64];
  int xoff;
  int ju;
  int iy;
  int i;
  boolean_T tst;
  double temp_re;
  double temp_im;
  int iheight;
  int istart;
  int j;
  double twid_re;
  double twid_im;
  int ihi;

#pragma omp parallel for \
 num_threads(omp_get_max_threads()) \
 private(rwork,xoff,ju,iy,i,tst,temp_re,temp_im,iheight,istart,j,twid_re,twid_im,ihi)

  for (k = 1; k < 65537; k++) {
    xoff = (k - 1) << 6;
    ju = 0;
    iy = 0;
    for (i = 0; i < 63; i++) {
      rwork[iy] = x[xoff];
      iy = 64;
      tst = true;
      while (tst) {
        iy >>= 1;
        ju ^= iy;
        tst = ((ju & iy) == 0);
      }

      iy = ju;
      xoff++;
    }

    rwork[iy] = x[xoff];
    for (i = 0; i <= 63; i += 2) {
      temp_re = rwork[i + 1].re;
      temp_im = rwork[i + 1].im;
      rwork[i + 1].re = rwork[i].re - rwork[i + 1].re;
      rwork[i + 1].im = rwork[i].im - rwork[i + 1].im;
      rwork[i].re += temp_re;
      rwork[i].im += temp_im;
    }

    iy = 2;
    xoff = 4;
    ju = 16;
    iheight = 61;
    while (ju > 0) {
      for (i = 0; i < iheight; i += xoff) {
        temp_re = rwork[i + iy].re;
        temp_im = rwork[i + iy].im;
        rwork[i + iy].re = rwork[i].re - temp_re;
        rwork[i + iy].im = rwork[i].im - temp_im;
        rwork[i].re += temp_re;
        rwork[i].im += temp_im;
      }

      istart = 1;
      for (j = ju; j < 32; j += ju) {
        twid_re = costab[j];
        twid_im = sintab[j];
        i = istart;
        ihi = istart + iheight;
        while (i < ihi) {
          temp_re = twid_re * rwork[i + iy].re - twid_im * rwork[i + iy].im;
          temp_im = twid_re * rwork[i + iy].im + twid_im * rwork[i + iy].re;
          rwork[i + iy].re = rwork[i].re - temp_re;
          rwork[i + iy].im = rwork[i].im - temp_im;
          rwork[i].re += temp_re;
          rwork[i].im += temp_im;
          i += xoff;
        }

        istart++;
      }

      ju /= 2;
      iy = xoff;
      xoff += xoff;
      iheight -= iy;
    }

    memcpy(&y[(k << 6) + -64], &rwork[0], sizeof(creal_T) << 6);
  }
}

//
// Arguments    : const double x[4194304]
//                const double costab[129]
//                const double sintab[129]
//                creal_T y[4194304]
// Return Type  : void
//
void r2br_r2dit_trig(const double x[4194304], const double costab[129], const
                     double sintab[129], creal_T y[4194304])
{
  int k;
  creal_T rwork[256];
  int xoff;

#pragma omp parallel for \
 num_threads(omp_get_max_threads()) \
 private(rwork,xoff)

  for (k = 1; k < 16385; k++) {
    xoff = (k - 1) << 8;
    r2br_r2dit_trig_impl(x, xoff, costab, sintab, rwork);
    memcpy(&y[(k << 8) + -256], &rwork[0], sizeof(creal_T) << 8);
  }
}

//
// File trailer for fft1.cpp
//
// [EOF]
//
